package com.fastbee.web.wnx;

import com.fastbee.web.wnx.service.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 生产实时表的 测试数据的定时器
 *
 * @author power
 */
@Component("wnxTask")
public class WnxSyncTask {

    private static final Logger log = LoggerFactory.getLogger(DatabaseMetaService.class);
    @Autowired
    private DatabaseMetaService databaseMetaService;
    @Autowired
    private MonthlySalesStatisticsService monthlySalesStatisticsService;
    @Autowired
    private ProductionEquipmentService productionEquipmentService;
    @Autowired
    private ProductOrderTimeService productOrderTimeService;
    @Autowired
    private WarehouseLocationService warehouseLocationService;
    @Autowired
    private  ProductionRawService productionRawService;
    @Autowired
    private WarehouseTimeService warehouseTimeService;
    @Autowired
    private WarehouseMadeStockService warehouseMadeStockService;
    @Autowired
    private WarehouseConsumableMaterialService warehouseConsumableMaterialService;
    @Autowired
    private  ProductRealOrderService productRealOrderService;
    @Autowired
    private  ProductionBadService productionBadService;
    @Autowired
    private  ProductionUnqualifiedService productionUnqualifiedService;
    @Autowired
    private  WarehouseMadeInventoryService warehouseMadeInventoryService;
    @Autowired
    private  WarehouseRawInventoryService warehouseRawInventoryService;
    @Autowired
    private  ProductionInspectionService productionInspectionService;
    @Autowired
    private  ProductionTeamService productionTeamService;
    @Autowired
    private ProductionEquipmentSotpService productionEquipmentSotpService;
    @Autowired
    private WarehouseCurrentService warehouseCurrentService;
    @Autowired
    private  ProductionStatusService productionStatusService;
    @Autowired
    private  ProductionBadNumberService productionBadNumberService;
    @Autowired
    private ProductReturnReasonService productReturnReasonService;
    @Autowired
    private ProductReturnService productReturnService;
    @Autowired
    private ProductPassService productPassService;
    @Autowired
    private PurchaseMaterialService purchaseMaterialService;
    @Autowired
    private PurchaseReturnService purchaseReturnService;
    @Autowired
    private ProductionPlanService productionPlanService;
    @Autowired
    private PurchaseOrderService purchaseOrderService;
    @Autowired
    private ProductRankingService productRankingService;
    @Autowired
    private PurchaseMonthlySalesService purchaseMonthlySalesService;
    @Autowired
    private ProductAbnormalOrderService productAbnormalOrderService;
    @Autowired
    private ProductBeforeOrderService productBeforeOrderService;
    @Autowired
    private ProductOrderMonthService productOrderMonthService;
    @Autowired
    private ProductHalfOrderService productHalfOrderService;
    @Autowired
    private SupplierAssessmentService supplierAssessmentService;
    @Autowired
    private WarehouseUseService warehouseUseService;
    @Value("${fastbee.syncWnx}")
    private String syncWnx;

    public void syncParams()
    {
        System.out.println("###########################");
        System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        Date date =  DateUtils.addDays(new Date(),-1); //new Date(); //DateUtils.parseDate("2025-11-26","yyyy-MM-dd");
        if(StringUtils.isNotBlank(syncWnx) && syncWnx.equals("true")){
            try {
                monthlySalesStatisticsService.loadMonthlySalesStatistics(date);
                productionEquipmentService.loadProductionEquipment(date);
                productOrderTimeService.loadProductOrderTime(date);
                warehouseLocationService.loadWarehouseLocation(date);
                productionRawService.loadProductionRaw(date);
                warehouseTimeService.loadWarehouseTime(date);
                warehouseMadeStockService.loadWarehouseMadeStock(date);
                warehouseConsumableMaterialService.loadWarehouseConsumableMaterial(date);
                productRealOrderService.loadProductRealOrder(date);
                productionBadService.loadProductionBad(date);
                productionUnqualifiedService.loadProductionUnqualified(date);
                warehouseMadeInventoryService.loadWarehouseMadeInventory(date);
                warehouseRawInventoryService.loadWarehouseRawInventory(date);
                productionInspectionService.loadProductionInspection(date);
                productionTeamService.loadProductionTeam(date);
                productionEquipmentSotpService.loadProductionEquipmentSotp(date);
                warehouseCurrentService.loadWarehouseCurrent(date);
                productionStatusService.loadProductionStatus(date);
                productionBadNumberService.loadProductionBadNumber(date);
                productReturnReasonService.loadProductReturnReason(date);
                productReturnService.loadProductReturn(date);
                productPassService.loadProductPass(date);
                purchaseReturnService.loadPurchaseReturn(date);
                productionPlanService.loadProductionPlan(date);
                purchaseOrderService.loadPurchaseOrder(date);
                productRankingService.loadProductRanking(date);
                purchaseMonthlySalesService.loadPurchaseMonthlySales(date);
                productAbnormalOrderService.loadProductAbnormalOrder(date);
                productBeforeOrderService.loadProductBeforeOrder(DateUtils.addDays(date, -1));
                productOrderMonthService.loadProductOrderMonth(date);
                productHalfOrderService.loadProductHalfOrder(date);
                supplierAssessmentService.loadSupplierAssessment(date);
                warehouseUseService.loadWarehouseUse(date);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
